package com.myaxuan.controller.permissions;

import com.myaxuan.entity.permissions.User;
import com.myaxuan.service.permissions.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by pc255 on 2018/1/31.
 */
@Controller
@RequestMapping("user")
public class UserController {


	@Autowired
	private UserService userService;


	@RequestMapping("index")
	public String index(){
		return "permissions/user";
	}


	@RequestMapping("page")
	@ResponseBody
	public List<User> findAll(@RequestParam(value="page" ,required = false ,defaultValue = "") Integer page ,
	                          @RequestParam(value="limit" ,required = false ,defaultValue = "")Integer limit){
		return userService.findAll(page,limit);
	}

	@RequestMapping("add")
	@ResponseBody
	public int insertUser(User user){
		return userService.insertSelective(user);
	}

	@RequestMapping("delete")
	@ResponseBody
	public int deleteUser(@RequestParam(value="id" ,required = false ,defaultValue = "") String id){
		return userService.deleteByPrimaryKey(id);
	}

	@RequestMapping("modify")
	@ResponseBody
	public int updateUser(User user){
		return userService.updateByPrimaryKeySelective(user);
	}

	@RequestMapping("single")
	@ResponseBody
	public User single(String id){
		return userService.selectByPrimaryKey(id);
	}

}
